<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("comctrls.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Vehicle_Edit2 extends Page
{
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $hfhr = null;
       public $hfod = null;
       public $JSMakeModel = null;
       public $Label7 = null;
       public $Label3 = null;
       public $Label12 = null;
       public $hfError = null;
       public $JSValidate = null;
       public $lblplate = null;
       public $lblyr = null;
       public $Label11 = null;
       public $Label10 = null;
       public $Label9 = null;
       public $edodometer = null;
       public $lblOd = null;
       public $edhours = null;
       public $cmbtrack = null;
       public $Button1 = null;
       public $hfcomp = null;
       public $cmbpersonnel = null;
       public $cmbownership = null;
       public $JTDivDept = null;
       public $JTGroupBox3 = null;
       public $btnAddDept = null;
       public $btnDelDept = null;
       public $edDept = null;
       public $listDept = null;
       public $JTDivType = null;
       public $JTGroupBox1 = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $JTDivGarage = null;
       public $JTGroupBox2 = null;
       public $btnAddGarage = null;
       public $btnDelGarage = null;
       public $edGarage = null;
       public $listGarage = null;
       public $edother = null;
       public $Label50 = null;
       public $cmbsize = null;
       public $Label8 = null;
       public $JTJavaScript9 = null;
       public $JTJavaScript8 = null;
       public $JTJavaScript7 = null;
       public $cmbDept = null;
       public $btnShowDept = null;
       public $uploadEmp = null;
       public $lblPhoto = null;
       public $btnCancel = null;
       public $btnUpdate = null;
       public $edCurrOd = null;
       public $lblCurrOd = null;
       public $lbltrackby = null;
       public $lblcustom1 = null;
       public $Memo1 = null;
       public $cmbvehop = null;
       public $btnShowType = null;
       public $Label6 = null;
       public $cmbclass = null;
       public $Label5 = null;
       public $edChassis = null;
       public $Label4 = null;
       public $edEngine = null;
       public $lblengine = null;
       public $lbldept = null;
       public $lbllocation = null;
       public $cmblocation = null;
       public $edveh = null;
       public $edyear = null;
       public $edcustomer = null;
       public $Label2 = null;
       public $lblownership = null;
       public $lbltype = null;
       public $cmbtype = null;
       public $lblmodel = null;
       public $cmbmodel = null;
       public $lblmnfr = null;
       public $cmbmanufacturer = null;
       public $edvin = null;
       public $Label1 = null;
       public $Label52 = null;
       public $JTHistory = null;
       public $JTDivChassis = null;
       public $btnChassishistory = null;
       public $btnDetails = null;
       public $JTSiteTheme1 = null;
       public $btnShowGarage = null;
       public $compid = null;
       public $JTJavaScript6 = null;
       public $JTJavaScript5 = null;
       public $JTJavaScript4 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $imgBack = null;
       public $Image3 = null;
       public $chkOutofService = null;
       public $hiddenLine = null;
       public $hiddenvehnum = null;
       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }

       function edvehJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edveh','lblplate');

       var edveh = document.getElementById('edveh').value;

       if(edveh.length>0)
       {
       regex_pattern = "[a-zA-Z][a-zA-Z][a-zA-Z][0-9][0-9][0-9]";
       var re = new RegExp(regex_pattern);
       var match = document.getElementById('edveh').value.match(re);
       if(match==null)
       {
        document.getElementById('lblplate').innerHTML = "&darr;&nbsp;Incorrect format - e.g.(ZTE168)&nbsp;&darr;";
       }
       }
       <?php

       }

       function edyearJSBlur($sender, $params)
       {

       ?>
       //Add your javascript code here
       validateRequire('edyear','lblyr');
       <?php

       }

       function btnCancelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.close();
       <?php

       }

       function Button1JSClick($sender, $params)
       {

       ?>
       var customer = document.getElementById('edcustomer_outer');
       var personnel = document.getElementById('cmbpersonnel_outer');
       alert(personnel.style.left);
       alert(customer.style.left);
       alert(personnel.style.visibility);
       alert(customer.style.visibility);
       <?php

       }

       function Vehicle_Edit2JSLoad($sender, $params)
       {

       ?>
       //alert('load');
       document.getElementById('edcustomer_outer').style.visibility = 'hidden';
       var comp = document.getElementById('hfcomp').value;
       var customer = document.getElementById('edcustomer_outer');
       var personnel = document.getElementById('cmbpersonnel_outer');
       var ownership = document.getElementById('cmbownership').value;

       if(ownership=='staff')
       {
       document.getElementById('edcustomer_outer').style.visibility = 'hidden';
       customer.style.left = '632px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'visible';
       personnel.style.left = '113px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'visible';
       }

       if(ownership=='company')
       {
       personnel.style.left = '632px';
       customer.style.left = '113px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'hidden';
       document.getElementById('edcustomer_outer').style.visibility = 'visible';
       document.getElementById('edcustomer').value = document.getElementById('hfcomp').value;
       }

       if(ownership=='leased' || ownership=='outsource')
       {
       personnel.style.left = '632px';
       customer.style.left = '113px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'hidden';
       document.getElementById('edcustomer_outer').style.visibility = 'visible';
       document.getElementById('edcustomer').value = '';
       }

         var od = document.getElementById('hfod').value;
        var hr = document.getElementById('hfhr').value;
        var tracking = document.getElementById("cmbtrack").value;
        if(tracking=='distance')
        {
        document.getElementById("edhours").disabled=true;
        document.getElementById("edhours").value='';
        document.getElementById("edhours").style.backgroundColor='#707070';
        document.getElementById("edodometer").style.backgroundColor='#000000';
        document.getElementById("edodometer").disabled=false;
        document.getElementById("edodometer").value=od;
        }
        if(tracking=='hours')
        {
        document.getElementById("edodometer").disabled=true;
        document.getElementById("edodometer").value='';
        document.getElementById("edodometer").style.backgroundColor='#707070';
        document.getElementById("edhours").style.backgroundColor='#000000';
        document.getElementById("edhours").disabled=false;
        document.getElementById("edhours").value=hr;
        }

       <?php

       }

       function cmbownershipJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       var comp = document.getElementById('hfcomp').value;
       var customer = document.getElementById('edcustomer_outer');
       var personnel = document.getElementById('cmbpersonnel_outer');
       var ownership = document.getElementById('cmbownership').value;
       //alert(document.getElementById('cmbownership').value);

       if(ownership=='staff')
       {
       document.getElementById('edcustomer_outer').style.visibility = 'hidden';
       customer.style.left = '577px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'visible';
       personnel.style.left = '113px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'visible';
       }

       if(ownership=='company')
       {
       personnel.style.left = '577px';
       customer.style.left = '113px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'hidden';
       document.getElementById('edcustomer_outer').style.visibility = 'visible';
       document.getElementById('edcustomer').value = document.getElementById('hfcomp').value;
       }

       if(ownership=='leased' || ownership=='outsource')
       {
       personnel.style.left = '577px';
       customer.style.left = '113px';
       document.getElementById('cmbpersonnel_outer').style.visibility = 'hidden';
       document.getElementById('edcustomer_outer').style.visibility = 'visible';
       document.getElementById('edcustomer').value = '';
       }
       <?php

       }



        function cmbsizeJSChange($sender, $params)
       {
          echo $this->cmbsize->ajaxCall("size");
          ?>
          //Add your javascript code here
          return false;
          <?php
       }

       function btnDelDeptJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var DeptIndex = document.getElementById('listDept').selectedIndex;
       var DeptValue = document.getElementById('listDept')[DeptIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxDept3(DeptValue,comp);
       <?php

       }

       function btnAddDeptJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var adddept = document.getElementById('edDept').value;
       var comp = document.getElementById('compid').value;
       AjaxDept2(adddept,comp);
       document.getElementById('edDept').value = "";
       <?php

       }

       function btnShowDeptJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivDept').Show();
       document.getElementById('edDept').value = "";
       <?php

       }
       function cmbmanufacturerJSChange($sender, $params)
       {
        //echo $this->cmbmanufacturer->ajaxCall('cmbmanufacturerChange');
        ?>
        makeModel();
        return false;
        <?php

       }

       function cmbtrackJSChange($sender, $params)
       {
        ?>
         var od = document.getElementById('hfod').value;
        var hr = document.getElementById('hfhr').value;
        var tracking = document.getElementById("cmbtrack").value;
        if(tracking=='distance')
        {
        document.getElementById("edhours").disabled=true;
        document.getElementById("edhours").value='';
        document.getElementById("edhours").style.backgroundColor='#707070';
        document.getElementById("edodometer").style.backgroundColor='#000000';
        document.getElementById("edodometer").disabled=false;
        document.getElementById("edodometer").value=od;
        }
        if(tracking=='hours')
        {
        document.getElementById("edodometer").disabled=true;
        document.getElementById("edodometer").value='';
        document.getElementById("edodometer").style.backgroundColor='#707070';
        document.getElementById("edhours").style.backgroundColor='#000000';
        document.getElementById("edhours").disabled=false;
        document.getElementById("edhours").value=hr;
        }

        return(false);

        <?php

       }

       function JTHistoryShow($sender, $params)
       {
        $query1 = "select * from chassis_history where veh_id='".$this->hiddenLine->getValue()."' order by datestamp desc";
        $result = mysql_query($query1)or die(mysql_error());

        $arr = array();
        while($row = mysql_fetch_array($result))
          {
            $arr[] = array(
                        'Chassis Num' => $row['chassis_num'],
                        'Date' => $row['datestamp']
                        );


          }

        $this->JTHistory->setCellData($arr);
        }

       function btnChassishistoryJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivChassis').Show();
       <?php

       }



       function btnDetailsJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var veh = document.getElementById("hiddenLine").value;
       alert(veh);
       window.open("veh_details.php?veh="+veh,"Window1",  "menubar=no,width=1079,height=850,left=200,top=230,toolbar=no scroll=yes");
       <?php

       }

       function btnDelGarageJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var dropdownIndex = document.getElementById('listGarage').selectedIndex;
       var dropdownValue = document.getElementById('listGarage')[dropdownIndex].value;
       var comp = document.getElementById('compid').value;
       AjaxGarage3(dropdownValue,comp);
       <?php

       }

       function btnAddGarageJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addgarage = document.getElementById('edGarage').value;
       var comp = document.getElementById('compid').value;
       AjaxGarage2(addgarage,comp);
       document.Vehicle_Edit.edGarage.value = "";
       <?php

       }

       function btnShowGarageJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivGarage').Show();
       document.Vehicle_Edit.edGarage.value = "";
       <?php

       }

       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var dropdownIndex = document.getElementById('listType').selectedIndex;
       var dropdownValue = document.getElementById('listType')[dropdownIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxMothercomp3(dropdownValue,compider3);
       <?php

       }

       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var compider = document.getElementById('compid').value;
       AjaxMothercomp2(addtype,compider);
       document.getElementById('edType').value = "";
       <?php

       }



       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
       document.getElementById('edType').value = "";
       <?php

       }


       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }



       function btnCancelClick($sender, $params)
       {
       redirect('vehicle_list.php');


       }



       function btnUpdateClick($sender, $params)
       {
       $this->validateRequired($this->edyear->Text, 'lblyr');

       $plate = $this->edveh->Text;

       if($plate=='')
       $this->validateRequired($this->edveh->Text, 'lblplate');

       if($plate!='')
       {
       if(!preg_match("/[a-zA-Z][a-zA-Z][a-zA-Z][0-9][0-9][0-9]/",$this->edveh->Text))
       {
        $this->lblplate->Caption = '&darr;&nbsp;Incorrect format - e.g.(ZTE168)&nbsp;&darr;';
        $this->hfError->setValue('1');
       }
       }

       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {
       if($this->chkOutofService->Checked==true)
       {
       $chkOutOfService = '1';
       }
       else
       {
       $chkOutOfService = '0';
       }

       $query_veh = "select * from vehicle_tbl where vehicle_id='".$this->hiddenLine->getValue()."'";
       $result_veh = mysql_query($query_veh)or die(mysql_error());
       $row_veh = mysql_fetch_array($result_veh);

       $style_id = $this->cmbtype->getItemIndex();
       $result_style = mysql_query("SELECT value FROM lookup_vehicle_tbl WHERE id='".$style_id."'") or die("ERROR STYLE ".mysql_error());
       $row_style = mysql_fetch_array($result_style);
       $style_name = $row_style['value'];

       $mnfr_id = $this->cmbmanufacturer->getItemIndex();
       $result_mnfr = mysql_query("SELECT * FROM lookup_vehicle_tbl WHERE company_id='".$_SESSION['company_id']."' and id='".$mnfr_id."'");
       $row_mnfr = mysql_fetch_array($result_mnfr);

       $own = $this->cmbownership->getItemIndex();
       if($own!='staff')
       {
       $owner = $this->edcustomer->Text;
       }
       if($own=='staff')
       {
       $owner = $this->cmbpersonnel->getItemIndex();
       }

       $track = $this->cmbtrack->getItemIndex();
       if($this->uploadEmp->FileExt=="")
       {
       if($track=='distance')
       {
       $query_update = "UPDATE vehicle_tbl SET
       VIN='".$this->edvin->Text."',
       manufacturer_name='".$row_mnfr['value']."',
       model_name='".$this->cmbmodel->getItemIndex()."',
       style_id='".$style_id."',
       style_name='".$style_name."',
       year='".$this->edyear->Text."',
       track_by='".$this->cmbtrack->getItemIndex()."',
       curr_tracking_value='".$this->edodometer->Text."',
       ownership='".$this->cmbownership->getItemIndex()."',
       customer='".$owner."',
       veh_num='".$this->edveh->Text."',
       engine_model='".$this->edEngine->Text."',
       chassis_num='".$this->edChassis->Text."',
       operator='".$this->cmbvehop->getItemIndex()."',
       location='".$this->cmblocation->getItemIndex()."',
       department='".$this->cmbDept->getItemIndex()."',
       custom1='".$this->Memo1->Text."',
       class='".$this->cmbclass->getItemIndex()."',
       size='".$this->cmbsize->getItemIndex()."',
       other='".$this->edother->Text."',
       out_of_service='".$chkOutOfService."'
       WHERE vehicle_id='".$this->hiddenLine->getValue()."'";
       mysql_query($query_update) or die(mysql_error());
       }
       if($track=='hours')
       {
       $query_update = "UPDATE vehicle_tbl SET
       VIN='".$this->edvin->Text."',
       manufacturer_name='".$row_mnfr['value']."',
       model_name='".$this->cmbmodel->getItemIndex()."',
       style_id='".$style_id."',
       style_name='".$style_name."',
       year='".$this->edyear->Text."',
       track_by='".$this->cmbtrack->getItemIndex()."',
       curr_hours='".$this->edhours->Text."',
       ownership='".$this->cmbownership->getItemIndex()."',
       customer='".$owner."',
       veh_num='".$this->edveh->Text."',
       engine_model='".$this->edEngine->Text."',
       chassis_num='".$this->edChassis->Text."',
       operator='".$this->cmbvehop->getItemIndex()."',
       location='".$this->cmblocation->getItemIndex()."',
       department='".$this->cmbDept->getItemIndex()."',
       custom1='".$this->Memo1->Text."',
       class='".$this->cmbclass->getItemIndex()."',
       size='".$this->cmbsize->getItemIndex()."',
       other='".$this->edother->Text."',
       out_of_service='".$chkOutOfService."'
       WHERE vehicle_id='".$this->hiddenLine->getValue()."'";
       mysql_query($query_update) or die(mysql_error());
       }
       }

       else
       {
       if($track=='distance')
       {
       $query_update = "UPDATE vehicle_tbl SET
       VIN='".$this->edvin->Text."',
       manufacturer_name='".$row_mnfr['value']."',
       model_name='".$this->cmbmodel->getItemIndex()."',
       style_id='".$style_id."',
       style_name='".$style_name."',
       year='".$this->edyear->Text."',
       track_by='".$this->cmbtrack->getItemIndex()."',
       curr_tracking_value='".$this->edodometer->Text."',
       ownership='".$this->cmbownership->getItemIndex()."',
       customer='".$owner."',
       veh_num='".$this->edveh->Text."',
       engine_model='".$this->edEngine->Text."',
       chassis_num='".$this->edChassis->Text."',
       operator='".$this->cmbvehop->getItemIndex()."',
       location='".$this->cmblocation->getItemIndex()."',
       department='".$this->cmbDept->getItemIndex()."',
       custom1='".$this->Memo1->Text."',
       class='".$this->cmbclass->getItemIndex()."',
       size='".$this->cmbsize->getItemIndex()."',
       other='".$this->edother->Text."',
       out_of_service='".$chkOutOfService."',
       photo ='"."photo/vehicle/veh".$this->hiddenLine->getValue().".".$this->uploadEmp->FileExt."'
       WHERE vehicle_id='".$this->hiddenLine->getValue()."'";
       mysql_query($query_update) or die(mysql_error());
       }

       if($track=='hours')
       {
       $query_update = "UPDATE vehicle_tbl SET
       VIN='".$this->edvin->Text."',
       manufacturer_name='".$row_mnfr['value']."',
       model_name='".$this->cmbmodel->getItemIndex()."',
       style_id='".$style_id."',
       style_name='".$style_name."',
       year='".$this->edyear->Text."',
       track_by='".$this->cmbtrack->getItemIndex()."',
       curr_hours='".$this->edhours->Text."',
       ownership='".$this->cmbownership->getItemIndex()."',
       customer='".$owner."',
       veh_num='".$this->edveh->Text."',
       engine_model='".$this->edEngine->Text."',
       chassis_num='".$this->edChassis->Text."',
       operator='".$this->cmbvehop->getItemIndex()."',
       location='".$this->cmblocation->getItemIndex()."',
       department='".$this->cmbDept->getItemIndex()."',
       custom1='".$this->Memo1->Text."',
       class='".$this->cmbclass->getItemIndex()."',
       size='".$this->cmbsize->getItemIndex()."',
       other='".$this->edother->Text."',
       out_of_service='".$chkOutOfService."',
       photo ='"."photo/vehicle/veh".$this->hiddenLine->getValue().".".$this->uploadEmp->FileExt."'
       WHERE vehicle_id='".$this->hiddenLine->getValue()."'";
       mysql_query($query_update) or die(mysql_error());
       }
       }

       $this->uploadEmp->moveUploadedFile("photo/vehicle/veh".$this->hiddenLine->getValue().".".$this->uploadEmp->FileExt);


       $chassis = $this->edChassis->Text;
       $old_chassis = $row_veh['chassis_num'];

       if($old_chassis!=$chassis)
       {
       $result_history = mysql_query("INSERT into chassis_history (company_id,
       veh_id,
       chassis_num)

       values('".$_SESSION['company_id']."',
        '".$this->hiddenLine->getValue()."',
        '".$this->edChassis->Text."')") or die(mysql_error());
       }

       if($old_chassis==$chassis)
       {
       }

       echo"<script language=javascript>
       alert('Successfully updated record!');
       window.opener.location.reload();
       window.close();
       </script>";
       //redirect("vehicle_list.php?id=".$this->hiddenLine->getValue());
       }

       }



       function cmbmaintenanceChange($sender, $params)
       {
       $maintenance = $this->cmbmaintenance->getItemIndex();
       $this->cmbmaintenance2->Clear();
       if ($maintenance=="employee")
       {
        $result5 = mysql_query("select lname from employee_tbl where job_title='fleet technician'");

        while($row5 = mysql_fetch_array($result5))
        {
            $this->cmbmaintenance2->AddItem($row5['lname'], null, $row4['lname']);
        }
       }
       else
       {
        $result6 = mysql_query("select vendor_name from vendor_tbl");

        while($row6 = mysql_fetch_array($result6))
        {
            $this->cmbmaintenance2->AddItem($row6['vendor_name'], null, $row6['vendor_name']);
        }
       }



       }


       function cmbmanufacturerChange($sender, $params)
       {

       $mnfr_id = $this->cmbmanufacturer->getItemIndex();
       $this->cmbmodel->Clear();
       $result4 = mysql_query("select model_name from lookup_models_tbl where company_id='".$_SESSION['company_id']."' and mnfr_id='".$mnfr_id."'");

       while($row4 = mysql_fetch_array($result4))
       {
            $this->cmbmodel->AddItem($row4['model_name'], null, $row4['model_name']);
       }

       }



       function cmbtrackChange($sender, $params)
       {
       $tracking = $this->cmbtrack->getItemIndex();
       if ($tracking=="distance")
       {
       $this->lblOd->Caption='Odometer:';
       $this->lblCurrOd->Caption='Curr Odometer';
       $save_here = "distance";
       }
       else
       {
       $this->lblOd->Caption='Hours:';
       $this->lblCurrOd->Caption='Curr hours';
       $save_here = "hours";
       }


       }


       function size()
      {
       $size = $this->cmbsize->getItemIndex();

       if($size=='other')
       {
       $this->edother->Enabled=true;
       }

       if($size!='other')
       {
       $this->edother->Enabled=false;
       $this->edother->Text='';
       }
      }

       function validateRequired($value, $lbl)
       {
          if($value == '' || $value == null)
          {
             $this->$lbl->Caption = '&darr; This field is required &darr;';
             $this->hfError->setValue('1');
          }
       }




       function Vehicle_Edit2Create($sender, $params)
       {

       $this->compid->Value = $_SESSION['company_id'];
       $this->hiddenLine->setValue($_GET['veh']);
       $this->hfError->setValue('0');

       $this->lblyr->Caption = '';
       $this->lblplate->Caption = '';

       $query1 = "select * from vehicle_tbl where vehicle_id='".$this->hiddenLine->getValue()."'";
       $result = mysql_query($query1)or die(mysql_error());
       $row = mysql_fetch_array($result);

       $result_comp = mysql_query("select * from company_tbl where company_id = '".$_SESSION['company_id']."'");
       $row_comp = mysql_fetch_array($result_comp);
       $this->hfcomp->setValue($row_comp['company_name']);


       if($row['size']=="other")
       {
       $this->edother->Enabled=true;
       }
       else
       {
       $this->edother->Enabled=false;
       $this->edother->Text='';
       }

       if($row['out_of_service']=="1")
       {
       $this->chkOutofService->Checked=true;
       }
       else
       {
       $this->chkOutofService->Checked=false;
       }

       $this->edvin->Text = $row['VIN'];
       $this->edyear->Text = $row['year'];
       $this->edcustomer->Text = $row['customer'];
       $this->edveh->Text = $row['veh_num'];
       $this->edEngine->Text = $row['engine_model'];
       $this->Memo1->Text = $row['custom1'];
       $this->edChassis->Text = $row['chassis_num'];
       //$this->edvehop->Text = $row['operator'];
       $this->cmbclass->setItemIndex($row['class']);
       //$this->edodometer->Text = $row['tracking_value'];
       $this->edodometer->Text = $row['curr_tracking_value'];
       $this->edhours->Text = $row['curr_hours'];
       $this->cmbtrack->ItemIndex = $row['track_by'];
       $this->cmbsize->ItemIndex = $row['size'];
       $this->edother->Text = $row['other'];
       $this->hfod->setValue($row['curr_tracking_value']);
       $this->hfhr->setValue($row['curr_hours']);

       $this->cmbvehop->Clear();
       $this->cmbvehop->ItemIndex=$row['operator'];
       $result_vehop = mysql_query("select * from employee_tbl where veh_op='1' and company_id='".$_SESSION['company_id']."'");

        while($row_vehop = mysql_fetch_array($result_vehop))
        {
            $this->cmbvehop->AddItem($row_vehop['lname'].','.$row_vehop['fname'], null, $row_vehop['lname'].','.$row_vehop['fname']);
        }



       $selected_mnfr = $row['manufacturer_name'];
       $result_sel_mnfr = mysql_query("SELECT * FROM lookup_vehicle_tbl WHERE value='".$selected_mnfr."' AND company_id='".$_SESSION['company_id']."'") or die("GET ID".mysql_error());
       $row_sel_mnfr = mysql_fetch_array($result_sel_mnfr);

       $this->cmbmanufacturer->Clear();

       $result_mnfr = mysql_query("select * from lookup_vehicle_tbl where company_id='".$_SESSION['company_id']."' and category='manufacturer' order by value asc");
       $this->cmbmanufacturer->AddItem($selected_mnfr, null, $row_sel_mnfr['id']);
       while($row_mnfr = mysql_fetch_array($result_mnfr))
        {
            if($selected_mnfr!=$row_mnfr['value'])
            $this->cmbmanufacturer->AddItem($row_mnfr['value'], null, $row_mnfr['id']);
        }
       $this->cmbmanufacturer->setItemIndex($row_sel_mnfr['id']);

       $this->cmbmodel->Clear();
       $selected_model = $row['model_name'];
       $this->cmbmodel->AddItem($selected_model, null, $selected_model);
       $result_model = mysql_query("select * from lookup_models_tbl where mnfr_id='".$row_sel_mnfr['id']."'");
       while($row_model = mysql_fetch_array($result_model))
       {
           $model = $row_model['model_name'];
           if($selected_model!=$model)
           $this->cmbmodel->AddItem($model, null, $model);
       }




        $this->cmbtype->ItemIndex=$row['style_id'];
        $result_style = mysql_query("select * from lookup_vehicle_tbl where company_id='".$_SESSION['company_id']."' AND category='body styles'");

        while($row_style = mysql_fetch_array($result_style))
        {
            $this->cmbtype->AddItem($row_style['value'], null, $row_style['id']);
        }

        //START OWNERSHIP
        $owner = $row['ownership'];
        $customer = $row['customer'];
        $this->cmbownership->ItemIndex = $owner;
        if($owner=='company' || $owner=='leased' || $owner=='outsource')
        {
        $this->edcustomer->Text = $customer;
        }

        if($owner=='staff')
        {
        $this->cmbpersonnel->ItemIndex = $customer;
        }


        $result_personnel = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_personnel = mysql_fetch_array($result_personnel))
        {
            $this->cmbpersonnel->AddItem($row_personnel['lname'].','.$row_personnel['fname'], null, $row_personnel['lname'].','.$row_personnel['fname']);
        }


        //END OWNERSHIP


        //chassis
       //$this->list_chassis->Clear();
       /* $result_chassis = mysql_query("select * from chassis_history where veh_id='".$this->hiddenLine->getValue()."' order by datestamp desc");


        while($row_chassis = mysql_fetch_array($result_chassis))
        {
            $this->ListChassis->AddItem($row_chassis['chassis_num'].'-'.$row_chassis['datestamp'], null, $row_chassis['chassis_num'].'-'.$row_chassis['datestamp']);
        }*/


         //list type
        $this->listType->Clear();
        $result_type = mysql_query("select * from lookup_vehicle_tbl where company_id='".$_SESSION['company_id']."' AND category='body styles'");


        while($row_type = mysql_fetch_array($result_type))
        {
            $this->listType->AddItem($row_type['value'], null, $row_type['id']);
        }

        /*$this->cmbownership->Clear();
        $this->cmbownership->ItemIndex = $row['ownership'];
        $result_ownership = mysql_query("select * from lookup_vehicle_tbl where category='ownership'");

        while($row_ownership = mysql_fetch_array($result_ownership))
        {
            $this->cmbownership->AddItem($row_ownership['value'], null, $row_ownership['value']);
        }*/




       /*$this->cmblocation->ItemIndex=$row['location'];
       $result_loc = mysql_query("select value from lookup_personnel_tbl where company_id='".$_SESSION['company_id']."' AND category='work locations'");

       while($row_loc = mysql_fetch_array($result_loc))
        {
            $this->cmblocation->AddItem($row_loc['value'], null, $row_loc['value']);
        }*/

        $this->cmblocation->ItemIndex=$row['location'];
        $result_loc = mysql_query("select * from company_garage where company_id='".$_SESSION['company_id']."'");

        while($row_loc = mysql_fetch_array($result_loc))
        {
            $this->cmblocation->AddItem($row_loc['name'], null, $row_loc['name']);
        }



        //list garage
        $this->listGarage->Clear();
        $result_garage = mysql_query("select value from lookup_personnel_tbl where company_id='".$_SESSION['company_id']."' AND category='work locations'");

        while($row_garage = mysql_fetch_array($result_garage))
        {
            $this->listGarage->AddItem($row_garage['value'], null, $row_garage['value']);
        }

        $this->cmbDept->ItemIndex=$row['department'];
        $result_department = mysql_query("select * from lookup_personnel_tbl where company_id = '".$_SESSION['company_id']."' AND category='departments'");

       while($row_department = mysql_fetch_array($result_department))
        {
            $this->cmbDept->AddItem($row_department['value'], null, $row_department['id']);
        }

        //list department
        $this->listDept->Clear();
        $result_dept = mysql_query("select * from lookup_personnel_tbl where company_id = '".$_SESSION['company_id']."' AND category='departments'");

        while($row_dept = mysql_fetch_array($result_dept))
        {
            $this->listDept->AddItem($row_dept['value'], null, $row_dept['id']);
        }

        /*$result = mysql_query("select employee_tbl.emp_id as employee_id,
        employee_tbl.lname as lname,
        employee_tbl.fname as fname
        from employee_tbl
        inner join emp_license_tbl
        on employee_tbl.emp_id = emp_license_tbl.emp_id
        where emp_license_tbl.vehicle_op='1'");

       while($row = mysql_fetch_array($result))
        {
            $this->cmboperator->AddItem($row['lname'].",".$row['fname'], null, $row['lname'].",".$row['fname']);
        } */


        /*$this->cmboperator->Clear();
        $this->cmboperator->ItemIndex=$row['operator'];
        $result_operator = mysql_query("select * from employee_tbl where company_id='".$_SESSION['company_id']."' and veh_op='1'");

        while($row_operator = mysql_fetch_array($result_operator))
        {
            $this->cmboperator->AddItem($row_operator['lname'].','.$row_operator['fname'], null, $row_operator['lname'].','.$row_operator['fname']);
        } */






        $this->imgBack->setLink('vehicle_list.php?company_id='.$_SESSION['company_id']);

       }

}

global $application;

global $Vehicle_Edit2;

//Creates the form
$Vehicle_Edit2=new Vehicle_Edit2($application);

//Read from resource file
$Vehicle_Edit2->loadResource(__FILE__);

//Shows the form
$Vehicle_Edit2->show();

?>